/*
 * SASettingItemList.cpp
 *
 *  Created on: 2010-06-04
 *      Author: NONO
 */



// System includes
#include <SMSAssist_0xEB692DC8.rsg>
#include <aknnotewrappers.h>                    // Misc. Notes
#include <EIKENV.h>
// User include
#include "SASettings.h"
#include "SASettingslistContainer.h"
#include "SA.hrh"

// Class include
#include "SASettingItemList.h"

// ================= MEMBER FUNCTIONS =======================

/**
* Constructor.  Takes a copy of the reference to aDifficultyLevel
* @param aDifficultyLevel the level of difficulty which will be set
*/  
CSASettingItemList::CSASettingItemList (CSASettings& aSettings,CSASettingslistContainer& aContainer)
: iSettings (aSettings),iContainer(aContainer),iFs(CEikonEnv::Static()->FsSession())
{
}

/**
*   
* Called by framework when the view size is changed.  Resizes the
* setting list accordingly.
*
*/
void CSASettingItemList::SizeChanged()
{
    if (ListBox()) 
        {
        ListBox()->SetRect(Rect());
        }
}
    
// ---------------------------------------------------------
// CSASettingItemList::HandleResourceChange()
// Called by framework when layout is changed.
// ---------------------------------------------------------
//
void CSASettingItemList::HandleResourceChange(TInt aType)
{
    CCoeControl::HandleResourceChange(aType);

    #if defined(__SERIES60_28__) || defined(__SERIES60_3X__)

    // ADDED FOR SCALABLE UI SUPPORT
    // *****************************
    if ( aType==KEikDynamicLayoutVariantSwitch )
        {
        TRect rect;
        AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
        SetRect(rect);
        }
        
    #endif
}



/**
*   
* Creates the actual setting items for the list, passing
* ownership of them to the calling class.  Each setting
* item has a piece of member data which it sets values in.
*/
CAknSettingItem* CSASettingItemList::CreateSettingItemL(TInt aIdentifier)
{
    CAknSettingItem* settingItem = NULL;
    
    switch (aIdentifier)
    {
        case ESASettingsListAutoRunItem:
		{
            settingItem = new (ELeave) CAknBinaryPopupSettingItem (aIdentifier, iSettings.AutoRun());
            iCurrentSettingList = ESettingList;
            break;
		}

        case ESASettingsListSneakModeItem:
		{
            settingItem = new (ELeave) CAknBinaryPopupSettingItem (aIdentifier, iSettings.SneakMode());
            break;
		}
    }
    return settingItem; // passing ownership
}

/**
* Causes the edit page for the currently selected setting
* item to be displayed
*/
void CSASettingItemList::ChangeSelectedItemL()
    {
        EditItemL(ListBox()->CurrentItemIndex(), ETrue);
    }

/**
* Called by the framework whenever an item is selected. 
* Causes the edit page for the currently selected setting item to be displayed and stores
* any changes made.
*/
void CSASettingItemList::EditItemL (TInt aIndex, TBool aCalledFromMenu)
{
    //General setting
    if (iCurrentSettingList == ESettingList)
    {
        CAknSettingItemList::EditItemL(aIndex, aCalledFromMenu);
        (*SettingItemArray())[aIndex]->StoreL();
    }
}
    
void CSASettingItemList::UpdateItemL(TInt aIndex,TBool aRedraw)
{
    (*SettingItemArray())[aIndex]->LoadL();
    if (aRedraw)
        (*SettingItemArray())[aIndex]->UpdateListBoxTextL();

}

void CSASettingItemList::SetItemFocus(TInt aIndex)
{
    
    ListBox()->SetCurrentItemIndexAndDraw(aIndex);

}
